package com.lin.boot.model;

import com.google.common.base.Strings;

import javax.persistence.*;

@Entity
@Table(name = "movies")
public class Movie {

    @Id
    @Column(name = "movie_id")
    private String movieId;

    @Column(name = "movie_name")
    private String movieName;

    @Transient
    private String[] genras;

    @Column(name = "movie_genras")
    private String genra;

    @Column(name = "movie_year")
    private Integer year;

    public String getMovieId() {
        return movieId;
    }

    public void setMovieId(String movieId) {
        this.movieId = movieId;
    }

    public String getMovieName() {
        return movieName;
    }

    public void setMovieName(String movieName) {
        this.movieName = movieName;
    }

    public String[] getGenras() {
        if (!Strings.isNullOrEmpty(this.genra)) {
            return genra.split("\\|");
        } else {
            return genras;
        }

    }

    public void setGenras(String[] genras) {
        this.genras = genras;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public String getGenra() {
        return genra;
    }

    public void setGenra(String genra) {
        this.genra = genra;
    }

    @Override
    public String toString() {
        return com.google.common.base.MoreObjects.toStringHelper(this)
                .add("movieId", movieId)
                .add("movieName", movieName)
                .add("genras", genras)
                .add("year", year)
                .toString();
    }
}
